package com.example.cores_middle_activity;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.Locale;

public class DatePickerView extends AppCompatActivity implements DatePickerDialog.OnDateSetListener {
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_date_picker_view);

        DatePicker datePicker = findViewById(R.id.dp);
        textView = findViewById(R.id.tv);
        Button button = findViewById(R.id.btn);
        Button selectBtn = findViewById(R.id.btn_slt);

        button.setOnClickListener(view -> {
            String format = String.format(Locale.CHINA, "您选择了%d年%d月%d日", datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            textView.setText(format);
        });


        selectBtn.setOnClickListener(view -> {
            Calendar calendar = Calendar.getInstance();
            // 创建日历组件
            DatePickerDialog datePickerDialog = new DatePickerDialog(this, this, 2024, 8, 8);
            datePickerDialog.show();
        });
    }

    @Override
    public void onDateSet(DatePicker datePicker, int year, int moth, int day) {
        String format = String.format(Locale.CHINA, "日历：%d年%d月%d日", year, moth, day);
        textView.setText(format);
    }
}